package com.atguigu.day05;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

// A --> B --> C
// \           ^
//  \         /
//   ---------

// var stream = source.map
// stream.filter.print
// stream.print
// source --> map --> filter --> print
//             \                   ^
//              \-----------------/
public class Example7 {
    public static void main(String[] args) {
        GraphNode A = new GraphNode("A");
        GraphNode B = new GraphNode("B");
        GraphNode C = new GraphNode("C");
        addEdge(A, B);
        addEdge(A, C);
        addEdge(B, C);

        HashMap<String, List<String>> graph = new HashMap<>();
        graph.put("A", Arrays.asList("B", "C"));
        graph.put("B", Arrays.asList("C"));
    }

    public static class GraphNode {
        public String name; // 顶点的名字
        public ArrayList<GraphNode> neighbors; // 顶点的邻居，顶点指向的其他顶点

        public GraphNode(String name) {
            this.name = name;
        }
    }

    public static void addEdge(GraphNode n1, GraphNode n2) {
        n1.neighbors.add(n2);
    }

    // 判断是否存在n1 --> n2的边
    public static boolean isExistEdge(GraphNode n1, GraphNode n2) {
        for (GraphNode node : n1.neighbors) {
            if (node.name.equals(n2.name))
                return true;
        }
        return false;
    }
}
